package org.biubiu0002.baiblog.core.controller;

import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.biubiu0002.baiblog.common.utils.PageUtils;
import org.biubiu0002.baiblog.common.utils.R;
import org.biubiu0002.baiblog.core.annotations.PermissionIgnore;
import org.biubiu0002.baiblog.core.model.entity.CommentRecordEntity;
import org.biubiu0002.baiblog.core.model.vo.req.CommentDeleteReqVo;
import org.biubiu0002.baiblog.core.service.CommentRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;



/**
 * 评论记录表
 *
 * @author biubiu0002
 * @email 1007918011@qq.com
 * @date 2022-05-06 00:50:37
 */
@RestController
@RequestMapping("/commentrecord")
public class CommentRecordController {
    @Autowired
    private CommentRecordService commentRecordService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("core:commentrecord:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = commentRecordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("core:commentrecord:info")
    public R info(@PathVariable("id") Long id){
		CommentRecordEntity commentRecord = commentRecordService.getById(id);

        return R.ok().put("commentRecord", commentRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("core:commentrecord:save")
    public R save(@RequestBody CommentRecordEntity commentRecord){
		commentRecordService.save(commentRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("core:commentrecord:update")
    public R update(@RequestBody CommentRecordEntity commentRecord){
		commentRecordService.updateById(commentRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @PermissionIgnore
    public R delete(@RequestBody CommentDeleteReqVo commentDeleteReqVo){
        Preconditions.checkArgument(StringUtils.isNotBlank(commentDeleteReqVo.getShareId()),"推文id不能为空");
        Preconditions.checkArgument(StringUtils.isNotBlank(commentDeleteReqVo.getCommentId()),"评论id不能为空");
        commentRecordService.delete(commentDeleteReqVo);
        return R.ok();
    }

}
